/*************************************************************************
 > File Name: monolith/interface/inference/model.cc
 > Author: dzhang
 > Mail: dong.zhang@ingenic.com
 > Created Time : Sun 17 Jan 2021 08:53:47 PM CST
 > Description:
 ************************************************************************/

#include "monolith/interface/inference/model.h"
#include "monolith/core/macros.h"

CC_NAME_SPACE_BEGIN
namespace inference {

Model::Model(ModelParameter model_parameter) {
    model_parameter_ = model_parameter;
    init_model();
}

Model::~Model() {
    model_interpreter_->releaseModel();
    model_interpreter_->releaseSession(model_session_);
}

int Model::init_model() {
    model_interpreter_ = std::shared_ptr<MNN::Interpreter>(
            MNN::Interpreter::createFromFile(
                    model_parameter_.model_path_.c_str()));
    MNN::ScheduleConfig config;
    config.numThread = model_parameter_.num_thread_;
    MNN::BackendConfig backendConfig;
    backendConfig.precision = (MNN::BackendConfig::PrecisionMode) 2;
    config.backendConfig = &backendConfig;
    model_session_ = model_interpreter_->createSession(config);
    input_tensor_ = model_interpreter_->getSessionInput(model_session_,
            nullptr);
    return 0;
}

} // namespace inference
CC_NAME_SPACE_END
